/* 
 * File:   PostingFile.cpp
 * Author: eduardo
 *
 * Created on 5 de noviembre de 2012, 21:02
 */

#include "PostingFile.h"

PostingFile::PostingFile() {
}

PostingFile::~PostingFile() {
    _postEntry.clear();
}

void PostingFile::insertElement(int key, const vector<DocOccurrence>& value) {
    if (!belongTo(key)) {
        _postEntry[key] = value;
    } else {
        vector<DocOccurrence>::const_iterator it = value.begin();
        while (it != value.end()) {
            insertElement(key, (*it));
        }
    }
}

// PASAR POR ARGUMENTO SI ESTABA O NO

void PostingFile::insertElement(int key, const DocOccurrence& value) {
    vector<DocOccurrence> vec;
    if (!belongTo(key)) {
        vec.push_back(value);
        _postEntry[key] = vec;
    } else {
        (_postEntry.find(key)->second).push_back(value);
    }
}

const vector<DocOccurrence>& PostingFile::getValue(int key) {
    return _postEntry.at(key);
}

void PostingFile::clear() {
    _postEntry.clear();
}

inline bool PostingFile::belongTo(int key) {
    return _postEntry.find(key) != _postEntry.end();
}